subroutine dpa_loop(lunit,cunit,ounit,dpa_cond,&
     total_time,total_dpa,total_sdpa,total_loop,temp,myrank)
  use param
  use table_param,only:n_event_table
  use table_param,only:spont_event_table
  use table_param,only:n_spont_event_table
  use edit_param,only:time_scale
  use edit_param,only:start_time
  use edit_param,only:time_width
  use edit_param,only:iter_width
  use global_param,only:loop_dpa
  use global_param,only:loop_sdpa
  implicit none

  integer,intent(in) :: lunit,cunit,ounit,myrank
  real(dbl),intent(in) :: dpa_cond,temp
  real(dbl),intent(inout) :: total_time,&
       total_dpa,total_sdpa,total_loop

  integer :: pick1,pick2,eid
  real(dbl) :: rn,dt,print_time
  real(dbl) :: elaps_time,elaps_loop,elaps_dpa,n_output

  elaps_time=0
  elaps_dpa=0
  elaps_loop=0
  n_output=0

  if (time_scale.eq.0) &
       call abnormal_stop("time_loop", &
       "The edit_param is not specified.")

  select case(time_scale)
  case(1)

     print_time=start_time

     if (print_time.eq.0) print_time=1.0e-30

     do while (n_event_table.gt.0)
        
        do while (n_spont_event_table.gt.0)
           call random_number(rn)
           eid=spont_event_table(&
                ceiling(rn*n_spont_event_table))
           call exe_event(lunit,cunit,eid)
        end do

        if (n_event_table.eq.0) exit

        call select_prob_event(lunit,eid,dt)

        loop_dpa=0
        loop_sdpa=0

        call exe_event(lunit,cunit,eid)

        elaps_time=elaps_time+dt
        total_time=total_time+dt
!        elaps_loop=elaps_loop+1
        total_loop=total_loop+1
        elaps_dpa=elaps_dpa+loop_dpa
        total_dpa=total_dpa+loop_dpa
        total_sdpa=total_sdpa+loop_sdpa

        if (elaps_time.ge.print_time) then
           do
              n_output=n_output+1
              call print_object(lunit,ounit,&
                   total_time,total_dpa,total_sdpa,total_loop,temp,&
                   n_output,myrank)
              print_time=print_time*10.0**time_width
              if (elaps_time.lt.print_time) exit
           end do
        end if

        if (elaps_dpa.ge.dpa_cond) exit

     end do

  case(2)

     print_time=start_time

     do while (n_event_table.gt.0)

        do while (n_spont_event_table.gt.0)
           call random_number(rn)
           eid=spont_event_table(&
                ceiling(rn*n_spont_event_table))
           call exe_event(lunit,cunit,eid)
        end do

        if (n_event_table.eq.0) exit

        call select_prob_event(lunit,eid,dt)

        loop_dpa=0
        loop_sdpa=0

        call exe_event(lunit,cunit,eid)

        elaps_time=elaps_time+dt
        total_time=total_time+dt
!        elaps_loop=elaps_loop+1
        total_loop=total_loop+1
        elaps_dpa=elaps_dpa+loop_dpa
        total_dpa=total_dpa+loop_dpa
        total_sdpa=total_sdpa+loop_sdpa

        if (elaps_time.ge.print_time) then
           do
              n_output=n_output+1
              call print_object(lunit,ounit,&
                   total_time,total_dpa,total_sdpa,total_loop,temp,&
                   n_output,myrank)
              print_time=print_time+time_width
              if (elaps_time.lt.print_time) exit
           end do
        end if

        if (total_dpa.ge.dpa_cond) exit

     end do

  case(3)

     print_time=0

     do while (n_event_table.gt.0)
        
        do while (n_spont_event_table.gt.0)
           call random_number(rn)
           eid=spont_event_table(&
                ceiling(rn*n_spont_event_table))
           call exe_event(lunit,cunit,eid)
        end do

        if (n_event_table.eq.0) exit

        call select_prob_event(lunit,eid,dt)

        loop_dpa=0
        loop_sdpa=0

        call exe_event(lunit,cunit,eid)

        elaps_time=elaps_time+dt
        total_time=total_time+dt
        elaps_loop=elaps_loop+1
        total_loop=total_loop+1
        elaps_dpa=elaps_dpa+loop_dpa
        total_dpa=total_dpa+loop_dpa
        total_sdpa=total_sdpa+loop_sdpa

        if (elaps_loop.ge.print_time) then
           n_output=n_output+1
           call print_object(lunit,ounit,&
                total_time,total_dpa,total_sdpa,total_loop,temp,&
                n_output,myrank)
           print_time=print_time+iter_width
        end if

        if (elaps_dpa.ge.dpa_cond) exit

     end do

  end select

  return

end subroutine dpa_loop
